﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace XMM.Controls.Library
{
    /// <summary>
    /// Interaktionslogik für Details_Series.xaml
    /// </summary>
    public partial class Details_Series : UserControl
    {
        Objects.Series SelectedSeries { get; set; }

        public Details_Series(Objects.Series oSelectedSeries)
        {
            InitializeComponent();

            SelectedSeries = oSelectedSeries;
        }

        public Details_Series(int iSeriesID)
        {
            InitializeComponent();

            SelectedSeries = new Objects.Series(iSeriesID);
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            Settings oSettings = new Settings();
            clearValues();

            if (SelectedSeries != null && SelectedSeries.SeriesID > 0)
            {
                Objects.Genre oGenre = new Objects.Genre(SelectedSeries.GenreID);

                lblSeriesTitle.Content = SelectedSeries.Name;
                lblGenre.Content = oGenre.Name;
                lblDirector.Content = SelectedSeries.Director;
                lblCast.Content = SelectedSeries.Cast;
                lblCast.ToolTip = SelectedSeries.Cast;
                txbPlot.Text = SelectedSeries.Plot;

                // Get CoverArt.
                string sCoverArtPath = oSettings.LibraryDataStorage + @"series\images\xmm_" + SelectedSeries.SeriesID.ToString() + ".jpg";
                if (System.IO.File.Exists(sCoverArtPath))
                {
                    BitmapImage bmpBanner = new BitmapImage(new Uri(sCoverArtPath, UriKind.Absolute));
                    imgCoverArt.Source = bmpBanner;
                    imgCoverArt.Stretch = Stretch.Uniform;
                }
            }
        }


        private void clearValues()
        {
            lblSeriesTitle.Content = String.Empty;
            lblGenre.Content = String.Empty;
            lblDirector.Content = String.Empty;
            lblCast.Content = String.Empty;
            imgCoverArt.Source = null;
            txbPlot.Text = String.Empty;
        }
    }
}
